package rai.portlet;

import javax.portlet.GenericPortlet;
import javax.portlet.ActionRequest;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderResponse;
import javax.portlet.PortletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.portlet.PortletRequestDispatcher;

import org.apache.log4j.Logger;
import rai.dao.*;
import rai.dto.AppDTO;
import rai.dto.CompanyDTO;
import rai.dto.EmployeeDTO;
import rai.dto.EmployeeInfoDTO;
import rai.dto.ExperienceDTO;
import rai.dto.FrwDTO;
import rai.dto.GradeDTO;
import rai.dto.LangDTO;
import rai.dto.ProjectEmpInfoDTO;
import rai.dto.TakenCourseDTO;
import rai.dto.TechDTO;
import rai.util.Constants;
import rai.util.ExportDataUtil;
import rai.blo.LoginBLO;
import rai.blo.RegFormBLO;
import rai.form.*;

/**
 * PITSPortlet Portlet Class.
 * @author Tien+Vu
 */
public class PITSPortlet extends GenericPortlet {
    /** Login Form. */
    private RegForm regform = new RegForm();
    private LoginForm loginForm = new LoginForm();
    private EditEmpInfoForm editEmpInfoForm = new EditEmpInfoForm();
    private EmployeeInfoForm empinfo = new EmployeeInfoForm();
    private EditTakenProject edittknPrj = new EditTakenProject();
    private EditTakenCourseForm edittknCourse = new EditTakenCourseForm();
    private EditExperienceForm editexp = new EditExperienceForm();
    private AddTakenProjForm addtknPrj = new AddTakenProjForm();
    private AddTakenCourseForm addtknCourse = new AddTakenCourseForm();
    private AddPrjFormAdmin addPrjAdmin = new AddPrjFormAdmin();
    private AddExpForm addexp= new AddExpForm();
    private EditProfileForm editprofile = new EditProfileForm();
    /** LoginBLO property. */
    private LoginBLO loginBLO;
    private boolean firstFlag = true;
    private String action = Constants.BLANK_VALUE;
    private int ID;
    private SearchInfoForm searchform = new SearchInfoForm();
    private ManageAccForm manAcc = new ManageAccForm();
    private EditAccForm editAcc = new EditAccForm();
    
    /**
     * Init Data for SearchForm.
     * @param searchform
     * @param request
     */
    private void initDataSearchForm(SearchInfoForm searchform,
            RenderRequest request) {

        String empname = searchform.getEmpName();
        String Compid = searchform.getComp();
        String Departid = searchform.getDep();
        String CompidIssued = searchform.getCompIssued();
        String DepartidIssued = searchform.getDepIssued();
        String Courseid = searchform.getCourse();
        String Grade = searchform.getGrade();
        String PrjComid = searchform.getPrjCom();
        String PrjDeptid = searchform.getPrjDept();
        String Prjid = searchform.getPrj();
        String Langid = searchform.getLang();
        String Appid = searchform.getApp();
        String Frwid = searchform.getFrw();
        String Techid = searchform.getTech();

        String empid = searchform.getEmpID();
        request.getPortletSession().setAttribute("lstCompID", Compid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstDept", Departid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstCompIssued", CompidIssued,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstDeptIssued",
                DepartidIssued, PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstCourse", Courseid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstGrade", Grade,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstPrjCom", PrjComid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstPrjDept", PrjDeptid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstPrj", Prjid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstLang", Langid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstApp", Appid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstFrw", Frwid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("lstTech", Techid,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute("PassingEmpID", empid,
                PortletSession.APPLICATION_SCOPE);
    }
    /**
     * Change format of Date to DD/MM/YYYY.
     * @param date
     * @return String
     */
    private String parseDate(String date) {
        return new String(date.substring(0, 2) + "/" + date.substring(2, 4)
                + "/" + date.substring(4, 8));
    }
    /** log property. */
    private static Logger log = Logger.getLogger("PITSPortlet");
    public void doView(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {
        PortletRequestDispatcher dispatcher;
        response.setContentType("text/html");
        log.info("doView.start");
        
        request.getPortletSession()
        .setAttribute(Constants.ERR_MESS_PORT_SESS_ATT,
                Constants.BLANK_VALUE,
                PortletSession.APPLICATION_SCOPE);
        request.getPortletSession().setAttribute(
                Constants.SUC_MESS_PORT_SESS_ATT,
                Constants.BLANK_VALUE,
                PortletSession.APPLICATION_SCOPE);
        
        // if the user access the page for the first time
        if (firstFlag) {
            log.debug("doView.firstFlag = true");
            request.getPortletSession().setAttribute(
                    Constants.ERR_MESS_PORT_SESS_ATT, "",
                    PortletSession.APPLICATION_SCOPE);
            response.setContentType("text/html");
            dispatcher = getPortletContext().getRequestDispatcher(
                    "/WEB-INF/jsp/PITSPortlet_view.jsp");
            dispatcher.include(request, response);
        } else {
            // Login Action
            log.debug("doView.firstFlag = false");
            log.info("Action is " + action);
            String tempid = (String) request.getPortletSession().getAttribute(
                    "PassingEmpID", PortletSession.APPLICATION_SCOPE);
            log.debug(tempid);
            //------------------------------------------LOGIN FORM------------------------
            if (action.equals(Constants.LOGIN_ACTION)) {
                log.debug("doView.action = login");
                request.getPortletSession().setAttribute("PassingEmpID", "",
                        PortletSession.APPLICATION_SCOPE);
                // validate the input data
                List<String> errorLst = loginForm.validateLogin(request,
                        response);
                // in case there is no error
                if (errorLst.isEmpty()) {
                    loginBLO = new LoginBLO();
                    // check whether isValidUser
                    if (loginBLO.isValidUser(loginForm.getUserName(), loginForm
                            .getPassword())) {
                        // set UserName and Role and return Employee Info
                        String Role = loginBLO.readRole(
                                loginForm.getUserName(), loginForm
                                        .getPassword());
                        log.info("User Role is " + Role);
                        if (Role.toLowerCase().equals("admin")) {
                            request.getPortletSession().setAttribute(
                                    Constants.ID_PORT_SESS_ATT, 0,
                                    PortletSession.APPLICATION_SCOPE);
                            request.getPortletSession().setAttribute(
                                    Constants.ROLE_PORT_SESS_ATT, Role,
                                    PortletSession.APPLICATION_SCOPE);
                            request.getPortletSession().setAttribute(
                                    Constants.NAME_PORT_SESS_ATT,
                                    loginForm.getUserName(),
                                    PortletSession.APPLICATION_SCOPE);
                            dispatcher = getPortletContext().getRequestDispatcher(
                                    Constants.ADMIN_MAN_ACC_PATH);
                            dispatcher.include(request, response);
                        } else if (Role.toLowerCase().equals("undefined")) {
                            log.info("Access Undefined Path");
                            dispatcher = getPortletContext().getRequestDispatcher(
                                    Constants.UNDEFINED_PATH);
                            dispatcher.include(request, response);
                        } else {
                            ID = loginBLO.readID(loginForm.getUserName(), loginForm
                                    .getPassword());
                            request.getPortletSession().setAttribute(
                                    Constants.ROLE_PORT_SESS_ATT, Role,
                                    PortletSession.APPLICATION_SCOPE);
                            request.getPortletSession().setAttribute(
                                    Constants.NAME_PORT_SESS_ATT,
                                    loginForm.getUserName(),
                                    PortletSession.APPLICATION_SCOPE);
                            request.getPortletSession().setAttribute(
                                    "PassingEmpID", "",
                                    PortletSession.APPLICATION_SCOPE);
                            EmployeeInfoDAO empInfoDAO = new EmployeeInfoDAO();
                            empInfoDAO.updateLogin(ID);
                            empInfoDAO.getEmpInfo(ID, request, response);
    
                            dispatcher = getPortletContext().getRequestDispatcher(
                                    Constants.EMP_INFO_VIEW_PATH);
                            dispatcher.include(request, response);
                        }
                    } else {
                        // Show error message in case user info is invalid
                        request.getPortletSession().setAttribute(
                                Constants.ERR_MESS_PORT_SESS_ATT,
                                "User info is invalid!",
                                PortletSession.APPLICATION_SCOPE);
                        // remove user name if any
                        request.getPortletSession().removeAttribute(
                                Constants.NAME_PORT_SESS_ATT);
                        dispatcher = getPortletContext().getRequestDispatcher(
                                Constants.LOGIN_VIEW_PATH);
                        dispatcher.include(request, response);
                    }
                } else {
                    // show error message in case UserName or password does not
                    // match the requirement
                    request.getPortletSession().setAttribute(
                            Constants.ERR_MESS_PORT_SESS_ATT, errorLst.get(0),
                            PortletSession.APPLICATION_SCOPE);
                    dispatcher = getPortletContext().getRequestDispatcher(
                            Constants.LOGIN_VIEW_PATH);
                    dispatcher.include(request, response);
                }
            }
            // Back to Login-Form
            if (action.equals(Constants.BACK_TO_LOGIN_FORM_ACTION)) {
                // remove error message if any
                request.getPortletSession().setAttribute("PassingEmpID", "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession()
                        .setAttribute(Constants.ERR_MESS_PORT_SESS_ATT,
                                Constants.BLANK_VALUE);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                                Constants.BLANK_VALUE);
                log.debug("doView.action = back_to_login_form");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.LOGIN_VIEW_PATH);
                dispatcher.include(request, response);
            }
            
            if (action.equals(Constants.BACK_TO_MAN_ACC)) {
                // remove error message if any
                request.getPortletSession().setAttribute("PassingEmpID", "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession()
                        .setAttribute(Constants.ERR_MESS_PORT_SESS_ATT,
                                Constants.BLANK_VALUE);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                                Constants.BLANK_VALUE);
                
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADMIN_MAN_ACC_PATH);
                dispatcher.include(request, response);
            }
            
            if (action.equals(Constants.ACCESS_TO_REGISTER_FORM_ACTION) 
                || action.equals(Constants.ACCESS_ADD_ACC)) {
                String role = (String)request.getPortletSession().getAttribute(
                        Constants.ROLE_PORT_SESS_ATT,
                        PortletSession.APPLICATION_SCOPE);
                if (role == null) {
                    request.getPortletSession().setAttribute(
                            Constants.ROLE_PORT_SESS_ATT, "",
                            PortletSession.APPLICATION_SCOPE);
                }
                request.getPortletSession().setAttribute(
                        Constants.ERR_MESS_PORT_SESS_ATT,
                        "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        "regEmpName",
                        "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        "regAddress",
                        "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        "regPhone",
                        "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        "regEmail",
                        "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        "regBirthday",
                        "01/01/1970",
                        PortletSession.APPLICATION_SCOPE);
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.REGISTER_VIEW_PATH);
                dispatcher.include(request, response);
            }
            
            if(action.equals(Constants.REGISTER_ACTION)) {
                log.debug("doView.action = register");
                List<String> errorLst = regform.validate(request, response);
                request.getPortletSession().setAttribute(
                        "regBirthday",
                        regform.getTxtBirthday(),
                        PortletSession.APPLICATION_SCOPE);
                if (errorLst.isEmpty()) {
                    RegFormBLO chk = new RegFormBLO();
                    if (!chk.checkUser(regform.getUserName())){
                        if (regform.validateEditEmpInfo(request, response).isEmpty()) {
                            RegFormDAO dao=new RegFormDAO();
                            boolean succ = dao.addData(regform);
                            if (succ) {
                                request.getPortletSession().setAttribute(
                                        Constants.NAME_PORT_SESS_ATT, regform.getUserName(),
                                        PortletSession.APPLICATION_SCOPE);
                                
                                request.getPortletSession().setAttribute(
                                        Constants.ERR_MESS_PORT_SESS_ATT,
                                        "Register successfully!!!",
                                        PortletSession.APPLICATION_SCOPE);
                            } else {
                                request.getPortletSession().setAttribute(
                                        Constants.ERR_MESS_PORT_SESS_ATT,
                                        "Register failed!!!",
                                        PortletSession.APPLICATION_SCOPE);
                            }
                            dispatcher = getPortletContext().getRequestDispatcher(
                                    Constants.REGISTER_VIEW_PATH);
                            dispatcher.include(request, response);
                        } else {
                            List<String> error = regform.validateEditEmpInfo(request, response);
                            request.getPortletSession().setAttribute(
                                    Constants.ERR_MESS_PORT_SESS_ATT,
                                    error.get(0),
                                    PortletSession.APPLICATION_SCOPE);
                            dispatcher = getPortletContext().getRequestDispatcher(
                                    Constants.REGISTER_VIEW_PATH);
                            dispatcher.include(request, response);
                        }
                        
                    }
                    else {
                        request.getPortletSession().setAttribute(
                                Constants.ERR_MESS_PORT_SESS_ATT,
                                "User Account has already existed!!",
                                PortletSession.APPLICATION_SCOPE);
                        request.getPortletSession().removeAttribute(
                                Constants.NAME_PORT_SESS_ATT);
                        dispatcher = getPortletContext().getRequestDispatcher(
                                Constants.REGISTER_VIEW_PATH);
                        dispatcher.include(request, response);
                    }
                }
                else {
                    request.getPortletSession().setAttribute(
                            Constants.ERR_MESS_PORT_SESS_ATT, errorLst.get(0),
                            PortletSession.APPLICATION_SCOPE);
                       
                    dispatcher = getPortletContext().getRequestDispatcher(
                            Constants.REGISTER_VIEW_PATH);
                    dispatcher.include(request, response);
                }
            }
            
          //------------------------------------------SEARCH FORM------------------------
            if (action.equals(Constants.BACK_TO_EMP_INFO_ACTION_1)) {
                log.debug("doView.action = back_to_empInfo_form_from_search");

                // reset data of Search-form
                searchform = new SearchInfoForm();
                request.getPortletSession().setAttribute("lstCompID", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstDept", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstCompIssued", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstDeptIssued", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstCourse", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstGrade", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstPrjCom", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstPrjDept", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstPrj", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstLang", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstApp", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstFrw", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("lstTech", "0",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("PassingEmpID", "",
                        PortletSession.APPLICATION_SCOPE);
                EmployeeInfoDAO empInfoDAO = new EmployeeInfoDAO();
                empInfoDAO.getEmpInfo(ID, request, response);
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EMP_INFO_VIEW_PATH);
                dispatcher.include(request, response);
            }
            
            if ((action.equals(Constants.ACCESS_TO_SEARCH_FORM_ACTION)) || (action.equals(Constants.RELOAD_SEARCH_ACTION))) {
                log.debug("doView.action = search_emp_info");
                SearchInfoDAO dao = new SearchInfoDAO();
                initDataSearchForm(searchform, request);

                log.info("Start CompanyList");
                List<CompanyDTO> list_comp = dao.getComp();
                request.getPortletSession().setAttribute("CompanyList",
                        list_comp, PortletSession.APPLICATION_SCOPE);
                log.info("Stop CompanyList");

                log.info("Start GradeList");
                List<GradeDTO> list_grade = dao.getGrade();
                request.getPortletSession().setAttribute("GradeList",
                        list_grade, PortletSession.APPLICATION_SCOPE);
                log.info("Stop GradeList");
                log.info("Start LangList");
                List<LangDTO> list_lang = dao.getLang();
                request.getPortletSession().setAttribute("LangList", list_lang,
                        PortletSession.APPLICATION_SCOPE);
                log.info("Stop LangList");
                log.info("Start AppList");
                List<AppDTO> list_app = dao.getApp();
                request.getPortletSession().setAttribute("AppList", list_app,
                        PortletSession.APPLICATION_SCOPE);
                log.info("Stop AppList");
                log.info("Start FrwList");
                List<FrwDTO> list_frw = dao.getFrw();
                request.getPortletSession().setAttribute("FrwList", list_frw,
                        PortletSession.APPLICATION_SCOPE);
                log.info("Stop FrwList");
                log.info("Start TechList");
                List<TechDTO> list_tech = dao.getTech();
                request.getPortletSession().setAttribute("TechList", list_tech,
                        PortletSession.APPLICATION_SCOPE);
                log.info("Stop TechList");
                log.info("Start ResultList");
                List<EmployeeDTO> list_result = new ArrayList<EmployeeDTO>();
                request.getPortletSession().setAttribute("ResultList",
                        list_result, PortletSession.APPLICATION_SCOPE);
                log.info("Stop ResultList");
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.SEARCH_INFO_PATH);
                dispatcher.include(request, response);
            }

            if (action.equals("do_search")) {
                SearchInfoDAO dao = new SearchInfoDAO();
                log.info("Start ResultList");
                initDataSearchForm(searchform, request);
                String empid = searchform.getEmpID();
                List<EmployeeDTO> list_result = dao.getresult(searchform);
                request.getPortletSession().setAttribute("ResultList",
                        list_result, PortletSession.APPLICATION_SCOPE);
                log.info("Stop ResultList");
                log.info("doView.stop");
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.SEARCH_INFO_PATH);
                dispatcher.include(request, response);

            }
            if (action.equals("get_back")) {
                
                log.info("Start ResultList");
                
                
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.SEARCH_INFO_PATH);
                dispatcher.include(request, response);

            }
            if (action.equals("go_to_empInfo")) {
                log.info("doView.stop");
                String empid = searchform.getEmpID();
                
                request.getPortletSession().setAttribute("PassingEmpID", empid,
                        PortletSession.APPLICATION_SCOPE);
                
                EmployeeInfoDAO empInfoDAO = new EmployeeInfoDAO();
                EmployeeInfoDTO emp = empInfoDAO.getAnotherEmpInfo(Integer
                        .parseInt(empid), request, response);

                request.getPortletSession().setAttribute("PassingEmpName",
                        emp.getName(), PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("PassingEmpBirthday",
                        emp.getBirthday(), PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("PassingEmpPhone",
                        emp.getPhone(), PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("PassingEmpEmail",
                        emp.getEmail(), PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("PassingEmpAddress",
                        emp.getAddress(), PortletSession.APPLICATION_SCOPE);

                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EMP_INFO_VIEW_PATH);
                dispatcher.include(request, response);
            }
            
            if (action.equals(Constants.EXPORT_ALL)) {
                log.info("Export All Result");
                //List<EmployeeDTO> lstResult = 
                //    (List<EmployeeDTO>) request.getPortletSession()
                //           .getAttribute("ResultList",
                //                            PortletSession.APPLICATION_SCOPE);
                ExportDataUtil exportUtil = new ExportDataUtil();
                log.info("Export All Result");
                SearchInfoDAO dao = new SearchInfoDAO();
                log.info("Export All Result");
                exportUtil.export(dao.getresult(searchform));
                log.info("Export All Result");
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.SEARCH_INFO_PATH);
                dispatcher.include(request, response);
                log.info("Stop Export All Result");
            }
          //------------------------------------------EDITPROFILE FORM------------------------
            if (action.equals(Constants.ACCESS_EDIT_PROFILE)) {
                
                String oldUserName = (String) request.getPortletSession()
                .getAttribute(Constants.NAME_PORT_SESS_ATT,
                        PortletSession.APPLICATION_SCOPE);
                editprofile.setTxtOldUserName(oldUserName);
                editprofile.setTxtUserName(oldUserName);
                request.getPortletSession()
                .setAttribute(Constants.ERR_MESS_PORT_SESS_ATT,
                        Constants.BLANK_VALUE);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        Constants.BLANK_VALUE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_PROFILE_PATH);
                dispatcher.include(request, response);
            }
            
            if (action.equals(Constants.EDIT_PROFILE_ACTION)) {
                Integer empID = (Integer) request.getPortletSession()
                .getAttribute(Constants.ID_PORT_SESS_ATT,
                        PortletSession.APPLICATION_SCOPE);
                EditProfileDAO dao = new EditProfileDAO();
                String errorMsg = dao.updateProfile(empID, editprofile);
                if (errorMsg.equals("Update Profile successfully!!!")) {
                    request.getPortletSession()
                        .setAttribute(Constants.NAME_PORT_SESS_ATT,
                                editprofile.getTxtUserName(),
                                PortletSession.APPLICATION_SCOPE);
                }
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        errorMsg,
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_PROFILE_PATH);
                dispatcher.include(request, response);
            }
          //------------------------------------------EMPINFO FORM------------------------
            if (action.equals(Constants.BACK_TO_EMP_INFO_ACTION_2)) {
                log.debug("doView.action = back_to_empInfo_form");
                // no reset passingEmpID
                EmployeeInfoDAO empInfoDAO = new EmployeeInfoDAO();
                empInfoDAO.getEmpInfo(ID, request, response);
                if (ID == 0) {
                    dispatcher = getPortletContext().getRequestDispatcher(
                            Constants.ADMIN_MAN_ACC_PATH);
                    dispatcher.include(request, response);
                } else {
                    dispatcher = getPortletContext().getRequestDispatcher(
                            Constants.EMP_INFO_VIEW_PATH);
                    dispatcher.include(request, response);
                }
            }
            // Access to Edit Personal Information Form
            if (action.equals(Constants.ACCESS_TO_EDIT_INFO_FORM_ACTION)) {
                log.debug("doView.action = access_to_edit_emp_info_form");
                String empid = (String) request.getPortletSession()
                        .getAttribute("PassingEmpID");
                log.debug("doView.action = access_to_edit_emp_info_form.begin"
                        + empid);
                if ((empid != null) && (!empid.equals(""))) {
                    log
                            .debug("doView.action = access_to_edit_emp_info_form.Ifbegin");
                    EmployeeInfoDAO empInfoDAO = new EmployeeInfoDAO();
                    EmployeeInfoDTO emp = empInfoDAO.getAnotherEmpInfo(Integer
                            .parseInt(empid), request, response);
                    request.getPortletSession().setAttribute("PassingEmpID",
                            emp.getID(), PortletSession.APPLICATION_SCOPE);
                    request.getPortletSession().setAttribute("PassingEmpName",
                            emp.getName(), PortletSession.APPLICATION_SCOPE);
                    request.getPortletSession().setAttribute(
                            "PassingEmpBirthday", emp.getBirthday(),
                            PortletSession.APPLICATION_SCOPE);
                    request.getPortletSession().setAttribute("PassingEmpPhone",
                            emp.getPhone(), PortletSession.APPLICATION_SCOPE);
                    request.getPortletSession().setAttribute("PassingEmpEmail",
                            emp.getEmail(), PortletSession.APPLICATION_SCOPE);
                    request.getPortletSession().setAttribute(
                            "PassingEmpAddress", emp.getAddress(),
                            PortletSession.APPLICATION_SCOPE);
                }
                log
                        .debug("doView.action = access_to_edit_emp_info_form.AccessBegin");
                request.getPortletSession()
                        .setAttribute(Constants.ERR_MESS_PORT_SESS_ATT,
                                Constants.BLANK_VALUE,
                                PortletSession.APPLICATION_SCOPE);
                request.getPortletSession()
                        .setAttribute(Constants.SUC_MESS_PORT_SESS_ATT,
                                Constants.BLANK_VALUE,
                                PortletSession.APPLICATION_SCOPE);
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_INFO_PATH);
                dispatcher.include(request, response);
            }
            
         // edit Taken Project Info
            if (action.equals(Constants.EDIT_TAKEN_PRJ_ACTION)) {
                Integer PrjID = empinfo.getId();
                Integer EmpID = (Integer) request.getPortletSession()
                        .getAttribute(Constants.ID_PORT_SESS_ATT,
                                PortletSession.APPLICATION_SCOPE);
                EditTakenProjectDAO dao = new EditTakenProjectDAO();
                ProjectEmpInfoDTO result = dao.getProject(PrjID, EmpID);
                this.edittknPrj.setId(PrjID);
                request.getPortletSession().setAttribute("TakenProjectInfo",
                        result, PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT, "",
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_TAKEN_PRJ_PATH);
                dispatcher.include(request, response);
            }
            
         // edit Taken Course
            if (action.equals(Constants.ACCESS_TO_EDIT_TKN_COURSE_FORM)) {
                Integer CourseID = empinfo.getCourseId();
                edittknCourse.setId(CourseID);
                Integer EmpID = (Integer) request.getPortletSession()
                        .getAttribute(Constants.ID_PORT_SESS_ATT,
                                PortletSession.APPLICATION_SCOPE);
                EditTakenCourseInfoDAO dao = new EditTakenCourseInfoDAO();
                TakenCourseDTO result = dao.getCourse(CourseID, EmpID);
                request.getPortletSession().setAttribute("TakenCourseInfo",
                        result, PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT, "",
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_TAKEN_COURSE_PATH);
                dispatcher.include(request, response);

            }
            
         // Access Edit Exp Form
            if (action.equals(Constants.ACCESS_TO_EDIT_EXP_FORM)) {
                Integer EmpID = (Integer) request.getPortletSession()
                        .getAttribute(Constants.ID_PORT_SESS_ATT,
                                PortletSession.APPLICATION_SCOPE);
                Integer DepartID = empinfo.getDepartId();
                EditExperienceDAO dao = new EditExperienceDAO();
                log.info("DepID " + DepartID + ":" + EmpID);
                ExperienceDTO result = dao.getExpInfo(DepartID, EmpID);
                log.info(result.getDepartID());
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT, "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("TakenExpInfo",
                        result, PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_EXP_PATH);
                dispatcher.include(request, response);
            }
            
            //Delete Exp
            if(action.equals(Constants.DEL_EMP_EXP_ACTION)){
                EmployeeInfoDAO dao = new EmployeeInfoDAO();
                Integer empID = (Integer) request.getPortletSession()
                .getAttribute(Constants.ID_PORT_SESS_ATT,
                        PortletSession.APPLICATION_SCOPE);
                dao.delete_Exp(this.empinfo.getChkExp(),empID);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EMP_INFO_VIEW_PATH);
                dispatcher.include(request, response);
            }
            
          //Delete Course
            if(action.equals(Constants.DEL_EMP_COURSE_ACTION)){
                EmployeeInfoDAO dao = new EmployeeInfoDAO();
                Integer empID = (Integer) request.getPortletSession()
                .getAttribute(Constants.ID_PORT_SESS_ATT,
                        PortletSession.APPLICATION_SCOPE);
                dao.delete_Course(this.empinfo.getChkCourse(),empID);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EMP_INFO_VIEW_PATH);
                dispatcher.include(request, response);
            }
          //Delete Project
            if(action.equals(Constants.DEL_EMP_PRJ_ACTION)){
                EmployeeInfoDAO dao = new EmployeeInfoDAO();
                Integer empID = (Integer) request.getPortletSession()
                .getAttribute(Constants.ID_PORT_SESS_ATT,
                        PortletSession.APPLICATION_SCOPE);
                dao.delete_Prj(this.empinfo.getChkPrj(),empID);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EMP_INFO_VIEW_PATH);
                dispatcher.include(request, response);
            }
          //Add Project
            if(action.equals(Constants.ADD_EMP_PRJ_ACTION)) {
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        "",
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADD_NEW_TAKEN_PRJ_PATH);
                dispatcher.include(request, response);
            }
           //Add Course
            if(action.equals(Constants.ADD_EMP_COURSE_ACTION)) {
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        "",
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADD_NEW_TAKEN_COURSE_PATH);
                dispatcher.include(request, response);
            }
          //Add Exp
            if(action.equals(Constants.ADD_EMP_EXP_ACTION)) {
                request.getPortletSession().setAttribute(
                        "compAdd",
                        "",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        "",
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADD_NEW_EXP_PATH);
                dispatcher.include(request, response);
            }
            
          //------------------------------------------UPDATE EMPINFO FORM------------------------
            if (action.equals(Constants.UPDATE_EMP_INFO_ACTION)) {
                log.debug("doView.action =update_emp_info");
                request.getPortletSession()
                        .setAttribute(Constants.ERR_MESS_PORT_SESS_ATT,
                                Constants.BLANK_VALUE,
                                PortletSession.APPLICATION_SCOPE);
                request.getPortletSession()
                        .setAttribute(Constants.SUC_MESS_PORT_SESS_ATT,
                                Constants.BLANK_VALUE,
                                PortletSession.APPLICATION_SCOPE);
                List<String> errorLst = editEmpInfoForm.validateEditEmpInfo(
                        request, response);
                if (!errorLst.isEmpty()) {
                    request.getPortletSession().setAttribute(
                            Constants.ERR_MESS_PORT_SESS_ATT, errorLst.get(0),
                            PortletSession.APPLICATION_SCOPE);
                } else {
                    EditEmpInfoDAO editEmpInfoDAO = new EditEmpInfoDAO();
                    String empid = (String) request.getPortletSession()
                            .getAttribute("PassingEmpID",
                                    PortletSession.APPLICATION_SCOPE);
                    log
                            .debug("doView.action = access_to_edit_emp_info_form.begin"
                                    + empid);
                    if ((empid != null) && (!empid.equals(""))) {
                        editEmpInfoDAO
                                .updateEmpInfo(Integer.parseInt(empid),
                                        editEmpInfoForm.getName(),
                                        editEmpInfoForm.getBirthday(),
                                        editEmpInfoForm.getAddress(),
                                        editEmpInfoForm.getEmail(),
                                        editEmpInfoForm.getPhone());
                    } else {
                        editEmpInfoDAO
                                .updateEmpInfo(ID, editEmpInfoForm.getName(),
                                        editEmpInfoForm.getBirthday(),
                                        editEmpInfoForm.getAddress(),
                                        editEmpInfoForm.getEmail(),
                                        editEmpInfoForm.getPhone());
                    }
                    request.getPortletSession().setAttribute(
                            Constants.SUC_MESS_PORT_SESS_ATT,
                            "Information updated successfully!",
                            PortletSession.APPLICATION_SCOPE);
                }
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_INFO_PATH);
                dispatcher.include(request, response);
            }
            
            
            
            //-----------------------------------------UPDATE PRJ FORM--------------------
            if (action.equals(Constants.UPDATE_TAKEN_PRJ_ACTION)) {
                Integer PrjID = edittknPrj.getId();
                Integer EmpID = (Integer) request.getPortletSession()
                        .getAttribute(Constants.ID_PORT_SESS_ATT,
                                PortletSession.APPLICATION_SCOPE);
                EditTakenProjectDAO dao = new EditTakenProjectDAO();
                log.info("EmpID " + EmpID + " PrjID " + PrjID);
                dao.updatePrj(edittknPrj, EmpID);
                ProjectEmpInfoDTO result = dao.getProject(PrjID, EmpID);
                request.getPortletSession().setAttribute("TakenProjectInfo",
                        result, PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        "Information updated successfully!",
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_TAKEN_PRJ_PATH);
                dispatcher.include(request, response);
            }
            
          //-----------------------------------------UPDATE COURSE FORM--------------------
            if (action.equals(Constants.UPDATE_TAKEN_COURSE_ACTION)) {
                Integer CourseID = empinfo.getCourseId();

                Integer EmpID = (Integer) request.getPortletSession()
                        .getAttribute(Constants.ID_PORT_SESS_ATT,
                                PortletSession.APPLICATION_SCOPE);
                String Grade = edittknCourse.getGrade();
                EditTakenCourseInfoDAO dao = new EditTakenCourseInfoDAO();
                if (Grade.equals("")) {
                    request.getPortletSession().setAttribute(
                            Constants.SUC_MESS_PORT_SESS_ATT,
                            "Grade must be filled!",
                            PortletSession.APPLICATION_SCOPE);
                } else {
                    dao.updateCourse(edittknCourse, EmpID);
                    request.getPortletSession().setAttribute(
                            Constants.SUC_MESS_PORT_SESS_ATT,
                            "Information updated successfully!",
                            PortletSession.APPLICATION_SCOPE);
                }
                TakenCourseDTO result = dao.getCourse(CourseID, EmpID);
                request.getPortletSession().setAttribute("TakenCourseInfo",
                        result, PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_TAKEN_COURSE_PATH);
                dispatcher.include(request, response);
            }
            
          //-----------------------------------------UPDATE EXP FORM--------------------
            if (action.equals(Constants.UPDATE_EXP_ACTION)) {
                Integer EmpID = (Integer) request.getPortletSession()
                        .getAttribute(Constants.ID_PORT_SESS_ATT,
                                PortletSession.APPLICATION_SCOPE);

                Integer DepartID = empinfo.getDepartId();
                log.info("DepID " + DepartID + ":" + EmpID);
                editexp.setoldDepartID(DepartID);
                EditExperienceDAO dao = new EditExperienceDAO();
                dao.updateexp(editexp, EmpID);
                ExperienceDTO result = dao.getExpInfo(editexp.getDepartID(),
                        EmpID);
                log.info(result.getDepartID());
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        "Information updated successfully!",
                        PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute("TakenExpInfo",
                        result, PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.EDIT_EXP_PATH);
                dispatcher.include(request, response);

            }
           //----------------------------------------ADD TKN PRJ FORM---------------------
            if(action.equals(Constants.ADD_NEW_EMP_PRJ_ACTION)) {
                EditTakenProjectDAO dao = new EditTakenProjectDAO();
                Integer empID = (Integer) request.getPortletSession()
                                    .getAttribute(Constants.ID_PORT_SESS_ATT,
                                        PortletSession.APPLICATION_SCOPE);
                Integer roleID = this.addtknPrj.getRoleName();
                Integer prjID = this.addtknPrj.getProjectID();
                String mess = dao.addPrj(empID, roleID, prjID);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        mess,
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADD_NEW_TAKEN_PRJ_PATH);
                dispatcher.include(request, response);
                
            }
            //----------------------------------------ADD TKN COURSE FORM---------------------
            if(action.equals(Constants.ADD_NEW_EMP_COURSE_ACTION)) {
                EditTakenCourseInfoDAO dao = new EditTakenCourseInfoDAO();
                Integer empID = (Integer) request.getPortletSession()
                                    .getAttribute(Constants.ID_PORT_SESS_ATT,
                                        PortletSession.APPLICATION_SCOPE);
                Integer courseID = this.addtknCourse.getCourseID();
                String grade = this.addtknCourse.getGrade();
                String mess = dao.addCourse(empID, grade, courseID);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        mess,
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADD_NEW_TAKEN_COURSE_PATH);
                dispatcher.include(request, response);
                
            }
            //-----------------------------------------ADD EMP EXP FORM-----------------------
            if(action.equals(Constants.ADD_NEW_EMP_EXP_ACTION)) {
                EditExperienceDAO dao = new EditExperienceDAO();
                Integer empID = (Integer) request.getPortletSession()
                                    .getAttribute(Constants.ID_PORT_SESS_ATT,
                                        PortletSession.APPLICATION_SCOPE);
                String mess = dao.addNewExp(this.addexp, empID);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        mess,
                        PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADD_NEW_EXP_PATH);
                dispatcher.include(request, response);
            }
            //-----------------------------------------VIEW PRJ INFO ------------------------
            if(action.equals(Constants.GOTO_PRJ_INFO)) {
                ProjectInfoDAO daoPrjInfo = new ProjectInfoDAO();
                Integer empID = (Integer) request.getPortletSession()
                .getAttribute(Constants.ID_PORT_SESS_ATT,
                    PortletSession.APPLICATION_SCOPE);
                ProjectEmpInfoDTO prjInfo = daoPrjInfo.getPrjInfo(
                        this.empinfo.getViewProjectID(), empID);
                request.getPortletSession().setAttribute("prjInfo", 
                        prjInfo,PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.VIEW_PRJ_INFO);
                dispatcher.include(request, response);
                
                
            }
            //----------------------------------------VIEW COURSE INFO------------------------
            if(action.equals(Constants.GOTO_COURSE_INFO)) {
                CourseInfoDAO daoCourseInfo = new CourseInfoDAO();
                Integer empID = (Integer) request.getPortletSession()
                .getAttribute(Constants.ID_PORT_SESS_ATT,
                    PortletSession.APPLICATION_SCOPE);
                TakenCourseDTO courseInfo = daoCourseInfo.getCourseInfo(
                        this.empinfo.getViewCourseID(), empID);
                request.getPortletSession().setAttribute("courseInfo", 
                        courseInfo,PortletSession.APPLICATION_SCOPE);
                response.setContentType("text/html");
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.VIEW_COURSE_INFO);
                dispatcher.include(request, response);
                
                
            }
            
            if (action.equals(Constants.ACCESS_EDIT_ACC)) {
                request.getPortletSession().setAttribute(
                            "editEmpID", manAcc.getEmpEditID(),                         
                            PortletSession.APPLICATION_SCOPE);
                request.getPortletSession().setAttribute(
                        "editUsername", manAcc.getEditUsername(),                         
                        PortletSession.APPLICATION_SCOPE);
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADMIN_EDIT_ACC_PATH);
                dispatcher.include(request, response);
            }
            
            if (action.equals(Constants.DEL_ACC)) {
                AdminActionDAO adminDAO = new AdminActionDAO();
                adminDAO.del_acc(manAcc.getAccArray());
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADMIN_MAN_ACC_PATH);
                dispatcher.include(request, response);
            }
            
            if (action.equals(Constants.EDIT_ACC)) {
                editAcc.setEmpID(manAcc.getEmpEditID());
                Integer empID = this.editAcc.getEmpID();
                String role = this.editAcc.getRole();
                AdminActionDAO adminDAO = new AdminActionDAO();
                adminDAO.edit_acc(empID, role);
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADMIN_MAN_ACC_PATH);
                dispatcher.include(request, response);
                
            }
            
            if (action.equals(Constants.RESET_PASS)) {
                Integer empID = this.editAcc.getEmpID();
                
                AdminActionDAO adminDAO = new AdminActionDAO();
                Integer newpass = adminDAO.reset_pass(empID);
                request.getPortletSession().setAttribute(
                        Constants.SUC_MESS_PORT_SESS_ATT,
                        "User's pass has been changed to " + newpass 
                        + " !Please inform him!",
                        PortletSession.APPLICATION_SCOPE);
                dispatcher = getPortletContext().getRequestDispatcher(
                        Constants.ADMIN_EDIT_ACC_PATH);
                dispatcher.include(request, response);
                
            }
            
            
            
        }
        log.info("doView.end");
    }

    public void doEdit(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {

        response.setContentType("text/html");

        PortletRequestDispatcher dispatcher = getPortletContext()
                .getRequestDispatcher("/WEB-INF/jsp/PITSPortlet_edit.jsp");
        dispatcher.include(request, response);

    }

    public void doHelp(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {

        response.setContentType("text/html");

        PortletRequestDispatcher dispatcher = getPortletContext()
                .getRequestDispatcher("/WEB-INF/jsp/PITSPortlet_help.jsp");
        dispatcher.include(request, response);

    }

    public void processAction(ActionRequest request, ActionResponse response)
            throws PortletException, IOException {
        firstFlag = false;
        loginForm = new LoginForm();
        editEmpInfoForm = new EditEmpInfoForm();
        log.info("processAction.start");
        if (request.getParameter("txtUserName") != null) {
            loginForm.setUserName(request.getParameter("txtUserName")
                    .toString());
            log.info("processAction.name=" + loginForm.getUserName());
        }
        if (request.getParameter("txtPassword") != null) {
            loginForm.setPassword(request.getParameter("txtPassword")
                    .toString());
            log.info("processAction.pass=" + loginForm.getPassword());
        }
        if (request.getParameter("txtAction") != null) {
            action = request.getParameter("txtAction").toString();
            log.info("processAction.action=" + action);
        }
        if (request.getParameter("txtEmpName") != null) {
            editEmpInfoForm.setName(request.getParameter("txtEmpName")
                    .toString());
            log.info("processAction.EmpName=" + editEmpInfoForm.getName());
        }
        if (request.getParameter("txtBirthday") != null) {
            editEmpInfoForm.setBirthday(request
                    .getParameter("txtBirthday").toString());
            log.info("processAction.Birthday=" + editEmpInfoForm.getBirthday());
        }
        if (request.getParameter("txtAddress") != null) {
            editEmpInfoForm.setAddress(request.getParameter("txtAddress")
                    .toString());
            log.info("processAction.Address=" + editEmpInfoForm.getAddress());
        }
        if (request.getParameter("txtEmail") != null) {
            editEmpInfoForm.setEmail(request.getParameter("txtEmail")
                    .toString());
            log.info("processAction.Email=" + editEmpInfoForm.getEmail());
        }
        if (request.getParameter("txtPhone") != null) {
            editEmpInfoForm.setPhone(request.getParameter("txtPhone")
                    .toString());
            log.info("processAction.Phone=" + editEmpInfoForm.getPhone());
        }
        //Register Form action
        if (action.equals(Constants.REGISTER_ACTION)) {
            
            if (request.getParameter("txtUserName") != null) {
                regform.setUserName(request.getParameter("txtUserName").toString());
                log.info("processAction.name=" + regform.getUserName());
            }
            if (request.getParameter("txtPassword") != null) {
                regform.setPassword(request.getParameter("txtPassword").toString());
                
            }
            if (request.getParameter("txtEmpName") != null) {
                regform.setTxtEmpName(request.getParameter("txtEmpName").toString());
                
            }
            if (request.getParameter("txtEmpAddress") != null) {
                regform.setTxtAddress(request.getParameter("txtEmpAddress").toString());
                
            }
            if (request.getParameter("txtEmpEmail") != null) {
                regform.setTxtEmail(request.getParameter("txtEmpEmail").toString());
                
            }
            if (request.getParameter("txtEmpPhone") != null) {
                regform.setTxtPhone(request.getParameter("txtEmpPhone").toString());
                
            }
            if (request.getParameter("txtEmpBirthday") != null) {
                regform.setTxtBirthday(parseDate(request
                        .getParameter("txtEmpBirthday").toString()));
            
            }
            if (request.getParameter("radioGender") != null) {
                regform.setRadioGender(Integer.parseInt(
                        request.getParameter("radioGender").toString()));
            
            }
            if (request.getParameter("lstDept") != null) {
                regform.setLstDept(Integer.parseInt(
                        request.getParameter("lstDept").toString()));
            
            }
            
        }
        //Edit Profile
        if (action.equals(Constants.EDIT_PROFILE_ACTION)) {
            
            if (request.getParameter("txtOldPassword") != null) {
                editprofile.setTxtOldPass(request.getParameter("txtOldPassword").toString());
                
            }
            if (request.getParameter("txtNewPassword") != null) {
                editprofile.setTxtNewPass(request.getParameter("txtNewPassword").toString());
                
            }
            
        }
        
        // Search Form action
        if (action.equals("do_search") || action.equals("go_to_empInfo")) {
            if (request.getParameter("txtEmpName") != null) {
                searchform.setEmpName(request.getParameter("txtEmpName"));
                log.info("value =" + request.getParameter("txtEmpName"));
            }
            if (request.getParameter("lstComp") != null) {
                searchform.setComp(request.getParameter("lstComp"));
                log.info("value =" + request.getParameter("lstComp"));
            }
            if (request.getParameter("lstDept") != null) {
                searchform.setDep(request.getParameter("lstDept"));
                log.info("value =" + request.getParameter("lstDept"));
            }

            if (request.getParameter("lstCompIssued") != null) {
                searchform.setCompIssued(request.getParameter("lstCompIssued"));
                log.info("value =" + request.getParameter("lstCompIssued"));
            }
            if (request.getParameter("lstDeptIssued") != null) {
                searchform.setDepIssued(request.getParameter("lstDeptIssued"));
                log.info("value =" + request.getParameter("lstDeptIssued"));
            }
            if (request.getParameter("lstCourse") != null) {
                searchform.setCourse(request.getParameter("lstCourse"));
                log.info("value =" + request.getParameter("lstCourse"));
            }
            if (request.getParameter("lstGrade") != null) {
                searchform.setGrade(request.getParameter("lstGrade"));
                log.info("value =" + request.getParameter("lstGrade"));
            }
            if (request.getParameter("lstPrjCom") != null) {
                searchform.setPrjCom(request.getParameter("lstPrjCom"));
                log.info("Prjvalue =" + request.getParameter("lstPrjCom"));
            }
            if (request.getParameter("lstPrjDept") != null) {
                searchform.setPrjDept(request.getParameter("lstPrjDept"));
                log.info("Prjvalue =" + request.getParameter("lstPrjDept"));
            }
            if (request.getParameter("lstPrj") != null) {
                searchform.setPrj(request.getParameter("lstPrj"));
                log.info("Prjvalue =" + request.getParameter("lstPrj"));
            }
            if (request.getParameter("lstLang") != null) {
                searchform.setLang(request.getParameter("lstLang"));
                log.info("value =" + request.getParameter("lstLang"));
            }
            if (request.getParameter("lstApp") != null) {
                searchform.setApp(request.getParameter("lstApp"));
                log.info("value =" + request.getParameter("lstApp"));
            }
            if (request.getParameter("lstTech") != null) {
                searchform.setTech(request.getParameter("lstTech"));
                log.info("value =" + request.getParameter("lstTech"));
            }
            if (request.getParameter("lstFrw") != null) {
                searchform.setFrw(request.getParameter("lstFrw"));
                log.info("value =" + request.getParameter("lstFrw"));
            }

            if (request.getParameter("txtAction") != null) {
                action = request.getParameter("txtAction");
                log.info("value =" + request.getParameter("txtAction"));
            }
            if (request.getParameter("txtLanghid") != null) {
                searchform.setLangtxt(request.getParameter("txtLanghid"));
                log.info("value =" + request.getParameter("txtLanghid"));
            }
            if (request.getParameter("txtApphid") != null) {
                searchform.setApptxt(request.getParameter("txtApphid"));
                log.info("value =" + request.getParameter("txtApphid"));
            }
            if (request.getParameter("txtTechhid") != null) {
                searchform.setTechtxt(request.getParameter("txtTechhid"));
                log.info("value =" + request.getParameter("txtTechhid"));
            }
            if (request.getParameter("txtFrwhid") != null) {
                searchform.setFrwtxt(request.getParameter("txtFrwhid"));
                log.info("value =" + request.getParameter("txtFrwhid"));
            }
            if (request.getParameter("txtEmpID") != null) {
                searchform.setEmpID(request.getParameter("txtEmpID"));
                log.info("valueEmpID =" + request.getParameter("txtEmpID"));
            }
        }
       if (action.equals(Constants.EDIT_TAKEN_PRJ_ACTION)) {
            if (request.getParameter("PassingProjectID") != null) {
                empinfo.setId(Integer.parseInt(request
                        .getParameter("PassingProjectID")));
            }
        }
        if (action.equals(Constants.UPDATE_TAKEN_PRJ_ACTION)) {
            if (request.getParameter("PeriodFrom") != null) {
                this.edittknPrj.setStart(parseDate(request
                        .getParameter("PeriodFrom")));
            }
            if (request.getParameter("PeriodTo") != null) {
                this.edittknPrj.setEnd(parseDate(request
                        .getParameter("PeriodTo")));
            }
            if (request.getParameter("lstRole") != null) {
                this.edittknPrj.setRole(Integer.parseInt(request
                        .getParameter("lstRole")));

            }
            if (request.getParameter("txtDes") != null) {
                this.edittknPrj.setDes(request.getParameter("txtDes"));
            }

        }
        if (action.equals(Constants.ACCESS_TO_EDIT_TKN_COURSE_FORM)) {
            if (request.getParameter("PassingCourseID") != null) {
                this.empinfo.setCourseId(Integer.parseInt(request
                        .getParameter("PassingCourseID")));
            }
        }
        if (action.equals(Constants.UPDATE_TAKEN_COURSE_ACTION)) {
            if (request.getParameter("periodFrom") != null) {
                this.edittknCourse.setDate(parseDate(request
                        .getParameter("periodFrom")));
            }
            if (request.getParameter("lstGrade") != null) {
                if (request.getParameter("lstGrade").equals("Other")) {
                    this.edittknCourse.setGrade(request
                            .getParameter("otherGrade"));
                } else {
                    this.edittknCourse.setGrade(request
                            .getParameter("lstGrade"));
                }
            }
        }
        if (action.equals(Constants.ACCESS_TO_EDIT_EXP_FORM)) {
            if (request.getParameter("PassingDepartID") != null) {
                empinfo.setDepartId(Integer.parseInt(request
                        .getParameter("PassingDepartID")));
            }
        }
        if (action.equals(Constants.UPDATE_EXP_ACTION)) {

            if (request.getParameter("lstDept") != null) {
                this.editexp.setDepartID(Integer.parseInt(request
                        .getParameter("lstDept")));
            }
            if (request.getParameter("periodFrom") != null) {
                this.editexp.setStartDate(parseDate(request
                        .getParameter("periodFrom")));
            }
            if (request.getParameter("periodTo") != null) {
                this.editexp.setEndDate(parseDate(request
                        .getParameter("periodTo")));
            }
            if (request.getParameter("lstRole") != null) {
                this.editexp.setRole(request.getParameter("lstRole"));
            }
            if (request.getParameter("txtDes") != null) {
                this.editexp.setDescription(request.getParameter("txtDes"));
            }
        }
        if(action.equals(Constants.DEL_EMP_EXP_ACTION)){
            if(request.getParameterValues("chkExp")!=null){
                this.empinfo.setChkExp(request.getParameterValues("chkExp"));
            }
        }
        if(action.equals(Constants.DEL_EMP_COURSE_ACTION)){
            if(request.getParameterValues("chkCourse")!=null){
                this.empinfo.setChkCourse(request.getParameterValues("chkCourse"));
            }
        }
        if(action.equals(Constants.DEL_EMP_PRJ_ACTION)){
            if(request.getParameterValues("chkPrj")!=null){
                this.empinfo.setChkPrj(request.getParameterValues("chkPrj"));
            }
        }
        if(action.equals(Constants.ADD_NEW_EMP_PRJ_ACTION)) {
            if(request.getParameter("lstPrj")!=null) {
                this.addtknPrj.setProjectID(Integer.parseInt(request.getParameter("lstPrj")));
            }
            if(request.getParameter("lstRole")!=null) {
                this.addtknPrj.setRoleName(Integer.parseInt(request.getParameter("lstRole")));
            }
        }
        if(action.equals(Constants.ADD_NEW_EMP_EXP_ACTION)) {
            if(request.getParameter("lstDept")!=null) {
                this.addexp.setDepartID(Integer.parseInt(request.getParameter("lstDept")));
            }
            if(request.getParameter("periodFrom")!=null) {
                this.addexp.setPeriodFrom(parseDate(request.getParameter("periodFrom")));
            }
            if(request.getParameter("periodTo")!=null) {
                this.addexp.setPeriodTo(parseDate(request.getParameter("periodTo")));
            }
            if(request.getParameter("lstRole")!=null) {
                this.addexp.setRoleID(Integer.parseInt(request.getParameter("lstRole")));
            }
            if(request.getParameter("txtDes")!=null) {
                this.addexp.setDes(request.getParameter("txtDes"));
            }
        }
        if(action.equals(Constants.ADD_NEW_EMP_COURSE_ACTION)) {
            if(request.getParameter("lstCourse")!= null) {
                this.addtknCourse.setCourseID(Integer.parseInt(request
                                                .getParameter("lstCourse")));
            }
            if (request.getParameter("lstGrade") != null) {
                if (request.getParameter("lstGrade").equals("Other")) {
                    this.addtknCourse.setGrade(request
                            .getParameter("otherGrade"));
                } else {
                    this.addtknCourse.setGrade(request
                            .getParameter("lstGrade"));
                }
            }
            
        }
        if(action.equals(Constants.GOTO_PRJ_INFO)) {
            if(request.getParameter("ViewProjectID") != null) {
                this.empinfo.setViewProjectID(Integer.parseInt(request.getParameter("ViewProjectID")));
            }
        }
        
        if(action.equals(Constants.GOTO_COURSE_INFO)) {
            if(request.getParameter("ViewCourseID") != null) {
                this.empinfo.setViewCourseID(Integer.parseInt(request.getParameter("ViewCourseID")));
            }
        }
        
        if(action.equals(Constants.ADD_NEW_PRJ_ADMIN)) {
            if(request.getParameter("lstComp")!=null) {
                addPrjAdmin.setComp(request.getParameter("lstComp"));
            }
            if(request.getParameter("lstDept")!=null) {
                addPrjAdmin.setDep(request.getParameter("lstDept"));
            }
            if(request.getParameter("txtDes")!=null) {
                addPrjAdmin.setTxtPrjDes(request.getParameter("txtDes"));
            }
            if(request.getParameter("txtSize")!=null) {
                addPrjAdmin.setSize(Integer.parseInt(request.getParameter("txtSize")));
            }
            if(request.getParameter("periodFrom")!=null) {
                addPrjAdmin.setPeriodFrom(parseDate(request.getParameter("periodFrom")));
            }
            if(request.getParameter("periodTo")!=null) {
                addPrjAdmin.setPeriodTo(parseDate(request.getParameter("periodTo")));
            }
            if (request.getParameter("txtLanghid") != null) {
                addPrjAdmin.setLangtxt(request.getParameter("txtLanghid"));
                
            }
            if (request.getParameter("txtApphid") != null) {
                addPrjAdmin.setApptxt(request.getParameter("txtApphid"));
                
            }
            if (request.getParameter("txtTechhid") != null) {
                addPrjAdmin.setTechtxt(request.getParameter("txtTechhid"));
                
            }
            if (request.getParameter("txtFrwhid") != null) {
                addPrjAdmin.setFrwtxt(request.getParameter("txtFrwhid"));
                
            }
            if (request.getParameter("txtPrjName") != null) {
                addPrjAdmin.setPrjName(request.getParameter("txtPrjName"));
                
            }
            if (request.getParameter("txtDatahid") != null) {
                addPrjAdmin.setTxtDatabase(request.getParameter("txtDatahid"));
                
            }
            
        }
        if (action.equals(Constants.ACCESS_ADD_ACC)) {
            
        }
        if (action.equals(Constants.EDIT_ACC)) {
            if(request.getParameter("lstRole") != null){
                this.editAcc.setRole(request.getParameter("lstRole"));
            }
            
            
        }
        
        if (action.equals(Constants.ACCESS_EDIT_ACC)) {
            if(request.getParameter("txtEmpID") != null){
                manAcc.setEmpEditID(Integer.parseInt(request.getParameter("txtEmpID")));
            }
            if(request.getParameter("txtEmpName") != null){
                manAcc.setEditUsername(request.getParameter("txtEmpName"));
            }
        }
        if (action.equals(Constants.DEL_ACC)) {
            if(request.getParameterValues("chkEmp")!=null){
                manAcc.setAccArray(request.getParameterValues("chkEmp"));
            }
        }
        if(action.equals(Constants.ADD_NEW_COURSE_ADMIN)) {
            
        }
        
        if(action.equals(Constants.ADD_NEW_DEPT_ADMIN)) {
            
        }
        
        if(action.equals(Constants.ADD_NEW_COMP_ADMIN)) {
            
        }
        
        log.info("processAction.end");
    }
}
